from django.db import models

# Create your models here.

from django.contrib.auth.models import User

class Greeting(models.Model):
    author = models.ForeignKey(User, null=True, blank=True)
    content = models.TextField()
    date = models.DateTimeField(auto_now_add=True)
    
class Location(models.Model):
    Name = models.CharField(max_length=50)
    x = models.IntegerField()
    y = models.IntegerField()
    
    def __unicode__(self):
        return u'%s' % (self.Name)

class CatInfo(models.Model):
    Name = models.CharField(max_length=50)
    Sex = models.IntegerField() #0 for female 1 for male 2 for unkonwn
    Portrait = models.TextField(max_length=1024) #image url
    lastLocation = models.ForeignKey(Location)
    Visits = models.IntegerField()#the total number of the cat page visits
    Father = models.ForeignKey('self', related_name = 'father', null = True, blank = True)
    Mother = models.ForeignKey('self', related_name = 'mother', null = True, blank = True)
    
    def __unicode__(self):
        return u'%s' % (self.Name)
    

class CatNews(models.Model):
    CatID = models.ForeignKey(CatInfo) #Cat ID
    Type = models.IntegerField() #0 for location
    #1 for treat   2 for photo update    3 for say something
    TargetID = models.IntegerField()


"""
    Oath User Model
"""
class OpenUser(models.Model):
    # the hidden 'id' is RenRenID
    Name = models.CharField(max_length=50)
    Access_Token = models.CharField(max_length=200)
    #UID = models.IntegerField()
    # photo uploaded is calculated dynamicly
    # default field id means UID
    
    def __unicode__(self):
        return u'%s' % (self.Name + str(self.UID))   
    
    

class CatImpression(models.Model):
    CatID = models.ForeignKey(CatInfo)
    UserID = models.ForeignKey(OpenUser)
    Content = models.CharField(max_length=50)
    Time = models.DateTimeField()
    
class Post(models.Model):
    Time = models.DateTimeField()
    Author = models.ForeignKey(OpenUser)
    Content = models.TextField()
    BelongID = models.IntegerField()#Belong ID
    

class Food(models.Model):
    Name = models.CharField(max_length = 50)

class Treat(models.Model):
    Time = models.DateTimeField()
    Author = models.ForeignKey(OpenUser)#open user ID
    CatID = models.ForeignKey(CatInfo)
    Food = models.ForeignKey(Food)
    
class Saying(models.Model):
    Time = models.DateTimeField()
    CatID = models.ForeignKey(CatInfo)
    Content = models.TextField()

class LocationInfo(models.Model):
    LocationID = models.ForeignKey(Location)
    Time = models.DateTimeField()
    CatID = models.ForeignKey(CatInfo)
    
# for special concerns
class Favorite(models.Model):
    CatID = models.ForeignKey(CatInfo)
    UserID = models.ForeignKey(OpenUser)
    Time = models.DateTimeField()#is the time is not too old, then sys will use this result, or sys will recalc the favorite

#for announcement post by the association
# enable rich text mode by using tinymce
class Announcement(models.Model):
    Headline = models.CharField(max_length=200)
    Time = models.DateTimeField()
    Article = models.TextField()
    #js = ('../static/js/tiny_mce/tiny_mce.js', '../static/js/textareas.js',)
    def __unicode__(self):
        return self.Headline
    
    class Admin:
        # various admin options are here
        js = (
             '../static/js/tiny_mce/tiny_mce.js',
            '../static/js/textareas.js',
        )

class AnnouncementComment(models.Model):
    Anno = models.ForeignKey(Announcement)
    UserID = models.ForeignKey(OpenUser)
    Time = models.DateTimeField()
    Content = models.TextField()
        
class Poll(models.Model):
    Title = models.CharField(max_length = 200)
    Time = models.DateTimeField()
    def __unicode__(self):
        return self.Title

class Choice(models.Model):
    Poll = models.ForeignKey(Poll)
    Text = models.CharField(max_length = 200)
    Votes = models.IntegerField()
    def __unicode__(self):
        return self.Text
    

class Photo(models.Model):
    URL = models.TextField(max_length=1024)
    CatID = models.ForeignKey(CatInfo)
    Time = models.DateTimeField()
    Author = models.ForeignKey(OpenUser)
    Title = models.TextField()
    Place = models.ForeignKey(LocationInfo)


class PhotoCatInclude(models.Model):
    CatID = models.ForeignKey(CatInfo)
    PhotoID = models.ForeignKey(Photo)
    Left = models.FloatField()
    Right = models.FloatField()
    Up = models.FloatField()
    Down = models.FloatField()

class PhotoComment(models.Model):
    PhotoID = models.ForeignKey(Photo)
    Time = models.DateTimeField()
    Author = models.ForeignKey(OpenUser)
    Content = models.TextField()
    ReplyTo = models.ForeignKey(OpenUser)

    
